<?php
/**
* 显示留存天数统计
*
* @copyright GZFeiYin 凡人项目开发团队
* @author phper wanghan
* @package
* @subpackage
* @version 2012-11-18
*/
require_once('../inc/config.php');
//开启memcache
$memcache = new Memcache;
$memcache->pconnect('127.0.0.1', 11211) or die ("Could not connect");

//获取日期
$st = $_GET['st'] == '' ? date('Y-m-d',strtotime('-8 day')) : $_GET['st'];
$et = $_GET['et'] == '' ? date('Y-m-d',strtotime('-1 day')) : $_GET['et'];

$sSql ="SELECT l.dDate,l.left_day,l.player_num,i.c_num FROM ".DB_FANREN2_ADMIN.".g_player_left l,".DB_FANREN2_ADMIN.".g_login_info i WHERE l.dDate=i.tday AND l.dDate>='".$st."' AND l.dDate<='".$et."' ORDER BY l.dDate DESC";
$rows = $db2->query_to_array($sSql);

//注册玩家总数
$sSql2 = "SELECT * FROM ".DB_FANREN2_ADMIN.".g_login_info WHERE tday <= '".$et."' order by tday asc";

$rs=$db2->query($sSql2);
$total_create_ok=0;
$total=array();
while($row=$db2->fetch_array($rs))
{
	$total_create_ok+=$row['c_num'];
	
	if($row['tday']>=$st)
	{			
		$total[$row['tday']] = $total_create_ok;	
		
	}
}

$aData = array();
foreach ($rows as $key=>$row){
	$aData[$row['dDate']]['new_reg'] = $row['c_num'];
	$aData[$row['dDate']]['total'] = $total[$row['dDate']];
	$aData[$row['dDate']][$row['left_day'].'day_left'] = round($row['player_num']/$row['c_num'],4)*100; 
}


include template('stat','stat_player_left');